// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cstdint>

#include <nebula/io/interfaces.h>
#include <turbo/base/macros.h>

namespace nebula::io {

    // Output stream that just writes to stdout.
    class TURBO_EXPORT StdoutStream : public OutputStream {
    public:
        StdoutStream();

        ~StdoutStream() override {}

        turbo::Status close() override;

        bool closed() const override;

        turbo::Result<int64_t> tell() const override;

        turbo::Status write(const void *data, int64_t nbytes) override;

    private:
        int64_t pos_;
    };

    // Output stream that just writes to stderr.
    class TURBO_EXPORT StderrStream : public OutputStream {
    public:
        StderrStream();

        ~StderrStream() override {}

        turbo::Status close() override;

        bool closed() const override;

        turbo::Result<int64_t> tell() const override;

        turbo::Status write(const void *data, int64_t nbytes) override;

    private:
        int64_t pos_;
    };

    // Input stream that just reads from stdin.
    class TURBO_EXPORT StdinStream : public InputStream {
    public:
        StdinStream();

        ~StdinStream() override {}

        turbo::Status close() override;

        bool closed() const override;

        turbo::Result<int64_t> tell() const override;

        turbo::Result<int64_t> read(int64_t nbytes, void *out) override;

        turbo::Result<std::shared_ptr<Buffer>> read(int64_t nbytes) override;

    private:
        int64_t pos_;
    };

}  // namespace nebula::io

